<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- portingqmlapp.qdoc -->
  <title>Porting QML Applications to Qt 5 Example | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Porting QML Applications to Qt 5 Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#related-topics">Related Topics</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Porting QML Applications to Qt 5 Example</h1>
<span class="subtitle"></span>
<!-- $$$portingqmlapp.html-description -->
<div class="descr"> <a name="details"></a>
<p>The new version of Qt Quick in Qt 5 brings in some changes to the way QML applications are developed. For the complete list of changes that affect existing QML applications, refer to <a href="qtquick-porting-qt5.html">Porting QML Applications to Qt 5</a>.</p>
<p>This topic will walk through the porting process to make the <code>flickr</code> Qt 4 QML demo work on Qt 5. If you have the SDK based on Qt 4.8 installed, you can find this demo application under <code>&lt;install_dir_root&gt;/Examples/4.x/declarative/demos/</code>.</p>
<p>Follow these step-by-step instructions to port the <i>flickr</i> Qt 4 QML application work to Qt 5:</p>
<ol class="1" type="1"><li>Open the <i>flickr</i> project using Qt Creator.</li>
<li>Edit all the <code>.qml</code> files and replace the <code>import QtQuick 1.0</code> statements with <code>import QtQuick 2.3</code>.</li>
<li>Add the additional <code>import QtQuick.XmlListModel 2.0</code> statement to <code>qml/common/RssModel.qml</code>.<p><b>Note: </b><a href="../qtxmlpatterns/qtquick-xmllistmodel-qmlmodule.html">XmlListModel</a> is part of a submodule under <code>QtQuick</code> and it must be imported explicitly in order to use it.</p></li>
<li>Make the following changes to <code>qmlapplicationviewer/qmlapplicationviewer.h</code>:<ul>
<li>Replace the <code>#include &lt;QtDeclarative/QDeclarativeView&gt;</code> with <code>#include &lt;QQuickView&gt;</code>.</li>
<li>Replace <code>QDeclarativeView</code> with <code>QQuickView</code> in the class declaration for <code>QmlApplicationViewer</code>.</li>
<li>Replace the parameter for <code>QmlApplicationViewer</code> constructor from <code>QWidget</code> to <code>QWindow</code>.</li>
</ul>
</li>
<li>Make the following changes to <code>qmlapplicationviewer/qmlapplicationviewer.cpp</code>:<ul>
<li>Replace all the <code>QtCore</code> and <code>QtDeclarative</code> include statements with these:<pre class="cpp">

  <span class="preprocessor">#include &lt;QCoreApplication&gt;</span>
  <span class="preprocessor">#include &lt;QDir&gt;</span>
  <span class="preprocessor">#include &lt;QFileInfo&gt;</span>
  <span class="preprocessor">#include &lt;QQmlComponent&gt;</span>
  <span class="preprocessor">#include &lt;QQmlEngine&gt;</span>
  <span class="preprocessor">#include &lt;QQmlContext&gt;</span>
  <span class="preprocessor">#include &lt;QDebug&gt;</span>

</pre>
</li>
<li>Replace all instances of <code>QWidget</code> with <code>QWindow</code>, and <code>QDeclarativeView</code> with <code>QQuickView</code>.</li>
<li>Remove the code between <code>#if defined(Q_OS_SYMBIAN)</code> and <code>#endif</code> macros as Symbian platform is not supported in Qt 5.</li>
<li>Remove the code between <code>#if QT_VERSION &lt; 0x040702</code> and <code>#else</code>, and <code>#endif // QT_VERSION &lt; 0x040702</code> macros towards the end.</li>
</ul>
</li>
<li>Save changes to the project and run the application.</li>
</ol>
<p>Once you see the application running, check whether it behaves as expected. Here is a snapshot of the application running on Ubuntu v12.04:</p>
<p class="centerAlign"><img src="images/flickr_application.png" alt="" /></p><a name="related-topics"></a>
<h2 id="related-topics">Related Topics</h2>
<p><a href="qtquick-porting-qt5.html">Porting QML Applications to Qt 5</a></p>
</div>
<!-- @@@portingqmlapp.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
